% -------------------------------------------------------------------------
% state dynamics
%
% ydot = fx_(t, y , auxdata)
%
% Input argumuents:
% -------------------------------------------------------------------------
% t             [1x1 double]          time                  [ TU ]        
% y             [7x1 double]          state variables       [ - ]
% auxdata       [structure]           parameters            [ - ]
%
% Output argumuents:
% -------------------------------------------------------------------------
% ydot          [7x1 double]          vector field          [ - ]
%
% External functions called:
% -------------------------------------------------------------------------
% None
%
% Copyright(C) 2015/06/22 by Chen Zhang, 
% School of Astronautics, Beihang University
% chenzhang.buaa@gmail.com
% -------------------------------------------------------------------------
function ydot = fx_(t, y , auxdata)
mu = auxdata.mu;
Tmax = auxdata.Tmax;
c = auxdata.c;
p = y(1); ex = y(2); ey = y(3);
hx = y(4); hy = y(5); L = y(6); m = y(7);

u = 0; 
ar = 0; au = 0; ah = 0;

W = 1 + ex * cos(L) + ey * sin(L);
Z = hx * sin(L) - hy * cos(L);
C = 1 + hx^2 + hy^2;

Ckep = sqrt(p / mu) / W;
A = Ckep * [0 ; 0 ; 0 ; 0 ; 0 ; W^3 * mu / p^2];
B = Ckep *  [0 , 2*p , 0;
    W * sin(L) , (W + 1) * cos(L) + ex , -Z * ey;
    -W * cos(L) , (W + 1) * sin(L) + ey, Z * ex;
    0 , 0 , C * cos(L) / 2;
    0 , 0 , C * sin(L) / 2;
    0 , 0 , Z];

% state dynamics
ydot = zeros(7 , 1);
ydot(1:6) = A + B * [ar ; au ; ah];
ydot(7) = - u * Tmax / c ;

end
% -------------------------------------------------------------------------
